package com.zzh.tree;

public class No701_insertIntoBST {
    public static void main(String[] args) {
        No701Solution solution = new No701Solution();
        TreeNode root = new TreeNode(5);
        root.left = new TreeNode(1);
        root.right = new TreeNode(7);
        root.right.left = new TreeNode(6);
        root.right.right = new TreeNode(8);
        solution.insertIntoBST(root,3);
        TreeNode.printTree(root);
    }
}
class No701Solution{
    public TreeNode insertIntoBST(TreeNode root, int val) {
        if (root==null){
            return new TreeNode(val);
        }
        if (root.val<val){
            root.right=insertIntoBST(root.right,val);
        }
        if (root.val>val){
            root.left=insertIntoBST(root.left,val);
        }
        return root;
    }
}
